<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld"%>
<!DOCTYPE html>
<html>
	<head>
		<title>菜单分配</title>
		<!-- 引入公用Js与Css -->
  		<%@include file="/view/common/resource.jsp" %>
  		 <!-- 引入jquery.tree Js与Css -->
	<script src="<%=basePath%>/js/plugins/jquery-tree/js/jquery.tree.js" type="text/javascript"></script>
  		<link rel="stylesheet" type="text/css" href="<%=basePath%>/js/plugins/jquery-tree/css/jquery.tree.css"/>
	</head>
	<body>
	
		<div id="wrap">
			<div style="margin-bottom:5px;" class="clearfix mt10 mr10 ml20">
				<form id="roleForm" class="form-horizontal" action="<%=basePath%>/sys/role/allotSave" method="post">
					<input type="hidden" name="id" value="${role.id }">
					<input type="hidden" id="checkedMenu" name="checkedMenu"> 
					<p class="radius3 bg_blue text-center w200 line-height30 mt10">
						<a href="javascript:" onclick="updateSave();" class="color_white show">确认分配</a>
					</p>
					<div id="tree"></div>
				</form>
		    </div>
		
		</div>
		<script type="text/javascript">
		
		var jsonData='${jsonData}';
		var baseUrl = '${baseUrl}';
	    $(document).ready(function(){
	    	var o = {
                showcheck: true,          
                //url: "http://jscs.cloudapp.net/ControlsSample/GetChildData" 
                theme: "bbit-tree-lines", //bbit-tree-lines ,bbit-tree-no-lines,bbit-tree-arrows
                showcheck: true,
                theme: "bbit-tree-arrows" //bbit-tree-lines ,bbit-tree-no-lines,bbit-tree-arrows
            };
            o.data = eval(jsonData);
            $("#tree").treeview(o);
	    });
	    
    	/* 数据保存 */
	    function updateSave() {
    		
    		// 将选中的菜单保存
    		$("#checkedMenu").val($("#tree").getTSVs());
    		
    	    var actionurl=$('#roleForm').attr('action');//提交路径
    	    
    	    $("#roleForm").ajaxSubmit({
    	    	type:"post",
    	    	url:actionurl,
    	    	dataType: "json",
    	    	success:function(data){
        	    	if (data.success) {
    	   	        	// 成功后跳转首页
    	   	            layer.msg("菜单分配成功", {icon: 6, time: 1000}, function() {
    	   	            	/* var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    	   	            	parent.layer.close(index); */
    	   	            	window.location.reload();
    	   	            });
    	   	        } else {
    	   	      		// 失败提醒
    	   	        	layer.msg(data.msg, {icon: 5});
    	   	        }
       	    	}
    	    }); 
	    }
    </script>
	</body>
</html>
